/**
**************************************************************************************
*Founder Effect                                                                      *
*Copyright (C) 2006-2007, 5d Studios (www.5d-Studios.com)                            *
*                                                                                    *
*This library is free software; you can redistribute it and/or                       *
*modify it under the terms of the GNU Lesser General Public                          *
*License as published by the Free Software Foundation; either                        *
*version 2.1 of the License, or (at your option) any later version.                  *
*                                                                                    *
*This library is distributed in the hope that it will be useful,                     *
*but WITHOUT ANY WARRANTY; without even the implied warranty of                      *
*MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU                   *
*Lesser General Public License for more details.                                     *
*                                                                                    *
*You should have received a copy of the GNU Lesser General Public                    *
*License along with this library; if not, write to the Free Software                 *
*Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA      *
**************************************************************************************
*/
#include "StdAfx.h"
#include "LUA_Label.h"
#include "../gui/GUI_Manager.h"
#include "../gui/MLabel.h"

LUA_Label::LUA_Label(lua_State *L) : LUA_Component(L)
{

}


/** Create a new dialog box */
int LUA_Label::Create( lua_State *L )
{
        // retrieve the name from lua
    std::string name   = luaL_checkstring( L, 1 );
    // retrieve the potential owner
    std::string sowner = luaL_checkstring( L, 2 );
    const gui::Component* owner = gui::GUI_Manager::GetInstance()->GetParentComponent( sowner );
    
    m_comp = new gui::MLabel( owner ); // might be NULL
    m_comp->SetName( name );

    if ( !owner )
        gui::GUI_Manager::GetInstance()->AddComponent( m_comp );
    
    return 0;
}

/** Set the text */
int LUA_Label::SetLabel( lua_State *L )
{
    if ( m_comp )
    {
        gui::MLabel* d = static_cast<gui::MLabel*>( m_comp );
        // retrieve the name from lua
        std::string name   = luaL_checkstring( L, 1 );
        d->SetLabelText( name );
    }
    return 0;

}
/** Get the text */
int LUA_Label::GetLabel( lua_State *L )
{
    if ( m_comp )
    {
        gui::MLabel* d = static_cast<gui::MLabel*>( m_comp );
        lua_pushstring( L, d->GetLabelText().c_str() ); 
        return 1;
    }
    return 0;

}


// -- Bind to LUA
#define method(class, name) {#name, &class::##name}

const char LUA_Label::className[] = "GUI_Label";
Lunar<LUA_Label>::RegType LUA_Label::methods[] = {
        method(LUA_Label, Create),
        method(LUA_Label, Destroy),
        method(LUA_Label, SetName),
        method(LUA_Label, GetName),
        method(LUA_Label, SetCaption),
        method(LUA_Label, GetCaption),
        method(LUA_Label, SetLocation),
        method(LUA_Label, GetLocation),
        method(LUA_Label, SetSize),
        method(LUA_Label, GetWidth),
        method(LUA_Label, GetHeight),
        method(LUA_Label, SetBackgroundColor),
        method(LUA_Label, GetBackgroundColor),
        method(LUA_Label, SetAlpha),
        method(LUA_Label, GetAlpha),
        method(LUA_Label, SetFocus),
        method(LUA_Label, HasFocus),
        method(LUA_Label, SetVisible),
        method(LUA_Label, IsVisible),

        method(LUA_Label, SetLabel),
        method(LUA_Label, GetLabel),
        method(LUA_Label, SetForegroundColor),
        method(LUA_Label, GetForegroundColor),
        {NULL, NULL}
};